function get_size_of_dir_in_bytes_with_robocopy ($directory)
{
  write-host "- $directory" -foreground "GREEN"
  [string]$result = robocopy /b /l /mir "$directory" "D:\temp" /r:0 /w:0 /ns /nc /nfl /ndl /njh /bytes
  if (!($lastexitcode -eq 16))
  {
    $pos = ($result).indexof("Bytes : ") # 字节
    $start = $pos + 8
    $length = $result.length
    $end = $length - $start
    $newstring = ($result).substring($start,$end)
    $newstring = $newstring.trim()
    $newstring -imatch "字节: .*? " 1>$null
    
    [int64]($Matches[0].split(':')[-1].trim())/1gb
  }
  else
  {
    echo "CANNOT ACCESS"
  }
}
get_size_of_dir_in_bytes_with_robocopy D:\ProgramFiles